﻿<?php require_once('../Connections/STN.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php include('componentes/enviafoto.class.php');?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
$codigopostagem=$_GET['postagem'];
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tb_postagens SET POS_TEXTO=%s, POS_TITULO=%s, POS_PER_CODIGO=%s, POS_PALAVRAS_CHAVES=%s WHERE POS_CODIGO='$codigopostagem'",
                       GetSQLValueString($_POST['POS_TEXTO'], "text"),
                       GetSQLValueString($_POST['POS_TITULO'], "text"),
                       GetSQLValueString($_POST['POS_PER_CODIGO'], "int"),
                       GetSQLValueString($_POST['POS_PALAVRAS_CHAVES'], "text"));

  mysql_select_db($database_STN, $STN);
  $Result1 = mysql_query($updateSQL, $STN) or die(mysql_error());

//altera a foto
if($_FILES['arquivo']['name']!=""){
	
	//fotos
	mysql_select_db($database_STN, $STN);
	$query_RSfotos = "SELECT ftp.* FROM tb_fotos_postagens ftp where ftp.FTP_POS_CODIGO='$codigopostagem';";
	$RSfotos = mysql_query($query_RSfotos, $STN) or die(mysql_error());
	$row_RSfotos = mysql_fetch_assoc($RSfotos);
	$totalRows_RSfotos = mysql_num_rows($RSfotos);
	
	$idfoto=$row_RSfotos['FTP_CODIGO'];	
	//enviador de foto
  	$resultadofoto = enviafoto("arquivo","/imagem.jpg","fotospostagem",800,600,1,"$idfoto");
}

  $updateGoTo = "postagem-lista.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}



//postagem
mysql_select_db($database_STN, $STN);
$query_RSpostagem = "SELECT pos.* FROM tb_postagens pos WHERE pos.POS_CODIGO='$codigopostagem';";
$RSpostagem = mysql_query($query_RSpostagem, $STN) or die(mysql_error());
$row_RSpostagem = mysql_fetch_assoc($RSpostagem);
$totalRows_RSpostagem = mysql_num_rows($RSpostagem);

//classificação
mysql_select_db($database_STN, $STN);
$query_RSper_cat = "select * from tb_periodos per join tb_categoriaS cat ON(cat.CAT_CODIGO=per.PER_CAT_CODIGO);";
$RSper_cat = mysql_query($query_RSper_cat, $STN) or die(mysql_error());
$row_RSper_cat = mysql_fetch_assoc($RSper_cat);
$totalRows_RSper_cat = mysql_num_rows($RSper_cat);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link  href="css/admin.css" rel="stylesheet" type="text/css" />
<title>Adiministrador</title>
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="../SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="../SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
<!--editor de texto-->
<script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
    tinyMCE.init({
        mode : "textareas",
        theme : "simple"
    });
</script>

</head>

<body>

<div id="main">
<div id="header">
            <a href="#" class="logo"><img src="img/logo.gif" width="101" height="29" alt="" /></a>
            <ul id="top-navigation">
                <li><a href="index.php">INDEX</a></li>
                <li><a href="postagem-lista.php"class="active">POSTAGENS</a></li>
                <li><a href="arquivos-lista.php">ARQUIVOS</a></li>
                <li><a href="album-lista.php">FOTOS ANTIGAS</a></li>
                <li><a href="videos-lista.php">VIDEOS</a></li>
            </ul>
			<div class="logout">
        	<a href="logout.php"><img src="img/logout.png" /></a>
            </div>
        </div>
        <div id="middle">
<div id="left-column">
                <h3>AULAS</h3>
                <ul class="nav">
                	
                    
<!--aulas-->                 	
				</ul>
                <a href="#" class="link">POSTAGEM PUBLICADAS</a>
                <a href="#" class="link">POSTAGEM ESCONDIDA</a>
            </div>
            <div id="center-column">
                <div class="top-bar">
                    <h1>CADASTRA POSTAGEM</h1>
                </div>
<!--conteudo-->
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">TÍTULO:</td>
      <td><span id="sprytextfield1">
        <input type="text" name="POS_TITULO" value="<?php echo $row_RSpostagem['POS_TITULO'] ?>" size="32" maxlength="200"/>
      <span class="textfieldRequiredMsg">O título e obrigatório.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">TEXTO:</td>
      <td><span id="sprytextarea1">
        <textarea name="POS_TEXTO" rows="30" cols="90"><?php echo $row_RSpostagem['POS_TEXTO'] ?></textarea>
      <span class="textareaRequiredMsg">O texto e obrigatório.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">CLASSIFICAÇÃO:</td>
      <td>
        <select name="POS_PER_CODIGO">
          <?php
do {  
?>
          <option value="<?php echo $row_RSper_cat['PER_CODIGO']?>"<?php if (!(strcmp($row_RSper_cat['PER_CODIGO'], $row_RSpostagem['POS_PER_CODIGO']))) {echo "selected=\"selected\"";} ?>><?php echo $row_RSper_cat['CAT_NOME']." - ".$row_RSper_cat['PER_NOME']?></option>
          <?php
} while ($row_RSper_cat = mysql_fetch_assoc($RSper_cat));
  $rows = mysql_num_rows($RSper_cat);
  if($rows > 0) {
      mysql_data_seek($RSper_cat, 0);
	  $row_RSper_cat = mysql_fetch_assoc($RSper_cat);
  }
?>
        </select>
      </td>
    </tr>
    <tr> </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">PALAVRAS CHAVES:</td>
      <td><input type="text" name="POS_PALAVRAS_CHAVES" value="<?PHP echo $row_RSpostagem['POS_PALAVRAS_CHAVES'] ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><label for="arquivo">Capa da postagem</label></td>
      <td>
      <input type="file" name="arquivo" id="arquivo" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Atualizar registro" /> <input type="button" value="Cancelar" onclick="javascript:history.back()" /> </td>
    </tr>
  </table>
  <input name="USU_CODIGO" type="hidden" value="<?php echo $_SESSION['codigo']; ?>"/>
  <input type="hidden" name="MM_insert" value="form1" />
  <input type="hidden" name="MM_update" value="form1" />
</form>
<!--fim do conteudo-->
</div>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1");
</script>
</div>
        <div id="footer"><p>&copy;COPYRIGHT <a href="http://twitter.com/jrnescau" target="_blank">Nescau</a> e <a href="http://twitter.com/JessuirCleydson" target="_blank">Jessuir</a> 2012. </p></div>
</div>
<?php
mysql_free_result($RSpostagem);
mysql_free_result($RSper_cat);

?>
